package com.example.cinema.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.cinema.entity.Hall;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.cinema.entity.Studios;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author yc138
 * @since 2024-08-26
 */
@Repository
public interface HallMapper extends BaseMapper<Hall> {

    @Results(id="rm1",
            value = {
                    @Result(column = "id",property = "id",id = true),
                    @Result(column = "stu_id",property = "stuId"),
                    @Result(column = "stu_id",property = "studios",
                            one =@One(
                            select="selectByStuIdStudios"
                    ))
            })
    @Select("select * from hall")
    List<Hall> selectAll(Page page);

    @Select("select * from studios where id=#{id}")
    Studios selectByStuIdStudios(int id);

////////
    @Select("select * from hall where stu_id = #{stuid}")
    @Results(id="queryHall",
            value = {
                    @Result(column = "id",property = "id",id = true),
                    @Result(column = "id",property = "schedules",many = @Many(
                            select="com.example.cinema.mapper.ScheduleMapper.querySchedule"
                    ))
            })
    Hall selectByStuId(int stuid);

    @Select("select * from hall")
    @Results(id = "rm2",value = {
            @Result(column = "id",property = "id",id = true),
            @Result(column = "stu_id",property = "stuId"),
            @Result(column = "stu_id",property = "studios",one = @One(
                    select = "com.example.cinema.mapper.StudiosMapper.selectById"
            ))
    })
    List<Hall> findAllByHall();

    @Select("select * from hall where id = #{id}")
    @Results(id = "rm3",value = {
            @Result(column = "id",property = "id",id = true),
            @Result(column = "stu_id",property = "stuId"),
            @Result(column = "stu_id",property = "studios",one = @One(
                    select = "com.example.cinema.mapper.StudiosMapper.selectById"
            ))
    })
    List<Hall> findAllByHid(int id);

}
